using (var mutex = new Mutex(false, "UbcXmlLib"))
            {
                try
                {
                    // Wait a few seconds if contended, in case another instance
                    // of the program is still in the process of shutting down.
                    bool isSuccess = false;
                    while (!isSuccess)
                    {
                        try
                        {
                            isSuccess = mutex.WaitOne(TimeSpan.FromSeconds(1), false);
                        }
                        catch (Exception ex)
                        {
                            mutex.ReleaseMutex();
                            throw ex;
                        }
                    }

                    //Access critical section.
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    mutex.ReleaseMutex();
                }